
<?php
class welcome{
		
	function __construct(){
			@$url = ($_GET['func'])=='' ? 'welcome' : $GET['func'];
			@$bb=$_GET['func'];
				if($bb == 'mes'){
				   $this->mes();
				}elseif($bb == 'admin'){
					$this->admin();
				}
				else{
					$this->fanye();
				}
				
	}
	    function admin(){
	    	require_once('./home/login.html');
		}
	
	
	
	
		function fanye(){
			/*
			 * 留言的分页*/
			 $page_size=5;
			 $sql2=mysql_query("SELECT count(id) FROM test_user");
			 $rel2=mysql_fetch_row($sql2);
			 $total=$rel2[0];
			 $page_max=ceil($total/$page_size);

	       if(!isset($_GET["page_num"]) || $_GET['page_num']>$page_max || $_GET['page_num']<1) {
	       	    $page_num=1;
	       }else{
	       	    $page_num=$_GET["page_num"];
	       }
		    $front=($page_num-1)*$page_size;
			$sql=mysql_query("select * from test_user order by id desc limit $front,$page_size ");
			$rel=mysql_fetch_object($sql);
			
			
			/*
			 * 的分页*/
			 $page_sizel=6;
			 $sql2l=mysql_query("SELECT count(id) FROM test_papapa ");
			 $rel2l=mysql_fetch_row($sql2l);
			 $totall=$rel2l[0];
			
			 $page_maxl=ceil($totall/$page_sizel);

	       if(!isset($_GET["page_numl"]) || $_GET['page_numl']>$page_maxl || $_GET['page_numl']<1) {
	       	    $page_numl=1;
	       }else{
	       	    $page_numl=$_GET["page_numl"];
	       }
		    $frontl=($page_numl-1)*$page_sizel;
			$sqll=mysql_query("select * from test_papapa order by id desc limit $frontl,$page_sizel ");
			$rell=mysql_fetch_object($sqll);			
			require_once('./home/static/welcome.php');
		}


		
		
		function mes(){
			if($_POST){
			$email=$_POST['email'];
			$title=$_POST['title'];
			$content=$_POST['content'];
			$addtime=time();
			if($email !='' && $title !='' && $content !=''&& $addtime!=''){
		  	$message_php = "insert into `test_user`(email,title,content,time)values('$email','$title','$content','$addtime')";
			    $result=mysql_query($message_php) or die('添加留言失败'.mysql_error());
				if($result>0){
					echo "<script>alert('发布成功');window.location.href='./' </script>";
				}else{
					echo "<script>alert('发布失败');window.location.href='./' </script>";
		            }
		        }else{
		        	echo "<script>alert('邮箱不能为空不能为空');window.location.href='./' </script>";
		        }
							
		            }
	            }

}
	?>